package com.dms.service;

import java.util.*;

import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.dms.dao.*;
import com.dms.model.*;
@Service
public class BuildingService {
	@Resource
	private BuildingDao dao;
	@Resource
	private TeacherService tService;
	public Building getBuilding(int id){
		String hql="from Building where id="+id;
		return dao.getBuilding(hql);
	}
	
	public void updateBuilding(Building building) {
		dao.updateBuilding(building);
	}
	
	public List<Building> getBuildingList(){
		String hql="from Building";
		return dao.getBuildings(hql);
	}
	
	public List<Building> searchBuilding(String name){
		String hql="from Building where name='"+name+"'";
//		System.out.println("searchBuilding hql="+hql);
		return dao.getBuildings(hql);
	}
	
	public void saveBuilding(Building building){
		dao.save(building);
	}
	
	public void deleteBuilding(int id){
		dao.delete(id);
	}
	
	public List<Building> getBuildingsByTeacher(int tId){
		List<Building> list=new ArrayList<Building>();
		Teacher teacher=tService.getTeacher(tId);
		List<TB> tbs=teacher.getTBs();
		for(TB tb:tbs){
			list.add(tb.getBuilding());
		}
		return list;
	}
	
	
}
